unit Class_MajorKey;

interface
uses
  Classes,SysUtils,Uni,UniEngine,IniFiles;

type
  TMajorKey=class(TUniEngine)
  private
    FMAJORKEY: string;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property MAJORKEY: string read FMAJORKEY write FMAJORKEY;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AMajorKey:TMajorKey):TMajorKey;overload;        
    class procedure CopyIt(AMajorKey:TMajorKey;var Result:TMajorKey);overload;

    class function  ExpSQL:string;      
  end;

implementation

{ TMajorKey }
procedure TMajorKey.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('MAJOR_KEY').Value := MAJORKEY; 
      end;
      otEdit:
      begin
        ParamByName('MAJOR_KEY').Value := MAJORKEY; 
      end;  
      otDelt:
      begin
        ParamByName('MAJOR_KEY').Value := MAJORKEY; 
      end;  
    end;
  end;
end;

function TMajorKey.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('GKX_GKJL_EL',['MAJOR_KEY',MAJORKEY],AUniConnection);
end;

function TMajorKey.GetNextIdex: Integer;
begin

end;

function TMajorKey.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TMajorKey.GetStrDelete: string;
begin
  Result:='DELETE FROM GKX_GKJL_EL WHERE   MAJOR_KEY=:MAJOR_KEY';
end;

function TMajorKey.GetStrInsert: string;
begin
  Result:='INSERT INTO GKX_GKJL_EL'
         +'    ( MAJOR_KEY)'
         +'    VALUES'
         +'    (:MAJOR_KEY)';
end;

function TMajorKey.GetStrsIndex: string;
begin
  Result:=Format('%S',[MAJORKEY]);
end;

function TMajorKey.GetStrUpdate: string;
begin
  raise Exception.Create('CAN NOT SUPPORT GETSTRUPDATE METHOD.CAUSE ALL THIS TABLE FILEDS ARE PRIMARY KEY.')
end;

constructor TMajorKey.Create;
begin

end;

destructor TMajorKey.Destroy;
begin

  inherited;
end;

class function TMajorKey.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TMajorKey.Create;
  with TMajorKey(Result) do
  begin
    MAJORKEY:=AUniQuery.FieldByName('MAJOR_KEY').AsString;
  end;  
end;

class procedure TMajorKey.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TMajorKey(Result) do
  begin
    MAJORKEY:=AUniQuery.FieldByName('MAJOR_KEY').AsString;
  end;  
end;

class function  TMajorKey.CopyIt(AMajorKey: TMajorKey): TMajorKey;
begin
  Result:=TMajorKey.Create;
  TMajorKey.CopyIt(AMajorKey,Result)
end;

class procedure TMajorKey.CopyIt(AMajorKey:TMajorKey;var Result:TMajorKey);
begin
  if Result=nil then Exit;
  Result.MAJORKEY:=AMajorKey.MAJORKEY;
end;

class function TMajorKey.ExpSQL: string;
begin
  Result:='SELECT MAJOR_KEY FROM GKX_GKJL_EL ORDER BY MAJOR_KEY';
end;

end.

